package com.cloudfun.campusshare.entity;

import com.cloudfun.campusshare.common.constant.OrderStatus;
import com.cloudfun.campusshare.common.constant.PayPlatform;
import com.cloudfun.campusshare.common.constant.ProductType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "device_order")
public class OrderEntity extends BaseEntity {

    @Id
    @GenericGenerator(name = "id_uuid", strategy = "uuid")
    @GeneratedValue(generator = "id_uuid")
    @Column(name = "id", unique = true, columnDefinition = ("varchar(40) not null comment '主键uuid'"))
    private String id;

    @Column(name = "user_id", columnDefinition = ("varchar(40) not null comment '用户Id'"))
    private String userId;

    @Column(name = "order_no", columnDefinition = ("varchar(40) not null comment '订单编号'"))
    private String orderNo;

    @Column(name = "order_status", columnDefinition = ("varchar(40) not null comment '订单状态'"))
    @Enumerated(EnumType.STRING)
    private OrderStatus orderStatus;

    @Column(name = "customer_id", columnDefinition = ("varchar(40) comment '顾客id'"))
    private String customerId;

    @Column(name = "customer_name", columnDefinition = ("varchar(40) comment '顾客名'"))
    private String customerName;

    @Column(name = "customer_phone", columnDefinition = ("varchar(20) comment '顾客手机号'"))
    private String customerPhone;

    @Column(name = "device_id", columnDefinition = ("varchar(40) not null comment '设备Id'"))
    private String deviceId;

    @JoinColumn(name = "device_id", referencedColumnName = "id", updatable = false, insertable = false)
    @ManyToOne(fetch = FetchType.LAZY)
    private DeviceEntity deviceEntity;

    @Column(name = "order_type", columnDefinition = ("int(1) default 0 comment '订单类型'"))
    private Integer orderType;

    @Column(name = "price", columnDefinition = ("int(10) not null comment '订单金额'"))
    private Integer price;

    @Column(name = "discount_price", columnDefinition = ("int(10) default 0 comment '优惠金额'"))
    private Integer discountPrice = 0;

    @Column(name = "handing_fee", columnDefinition = ("int(10) default 0 comment '手续费'"))
    private Integer handingFee = 0;

    @Column(name = "settlement_amount", columnDefinition = ("int(10) default 0 comment '结算金额'"))
    private Integer settlementAmount = 0;

    @Column(name = "actual_pay_amount", columnDefinition = ("int(10) default 0 comment '实际支付金额（用户支付成功后才会设置）'"))
    private Integer actualPayAmount = 0;

    @Column(name = "project_id", columnDefinition = ("varchar(40) default null comment '项目id'"))
    private String projectId;

    @Column(name = "trade_time", columnDefinition = ("varchar(14) default null comment '下单时间'"))
    private String tradeTime;

    @Column(name = "complete_time", columnDefinition = ("varchar(14) default null comment '订单结束时间'"))
    private String completeTime;

    @Column(name = "cost_time", columnDefinition = ("int(11) default null comment '使用时间(单位：分钟)'"))
    private Integer costTime;

    @Column(name = "order_name", columnDefinition = ("varchar(64) default null comment '订单名称'"))
    private String orderName;

    @Column(name = "mode_id", columnDefinition = ("varchar(40) default null comment '模式id'"))
    private String modeId;

    @Column(name = "is_subscribe", columnDefinition = ("tinyint(1) default 0 comment '是否是预约单'"))
    private Boolean isSubscribe = false;

    @Column(name = "service_time", columnDefinition = ("int(11) default null comment '服务时长(单位：分钟)'"))
    private Integer serviceTime;

    @Column(name = "product_type", columnDefinition = ("varchar(40) default null comment '产品类型'"))
    @Enumerated(EnumType.STRING)
    private ProductType productType;

    @Column(name = "belong_merchant_name", columnDefinition = ("varchar(64) default null comment '所属商家名称'"))
    private String belongMerchantName;

    @Column(name = "wash_point_id", columnDefinition = ("varchar(40) default null comment '洗衣点Id'"))
    private String washPointId;

    @Column(name = "wash_point_name", columnDefinition = ("varchar(64) default null comment '洗衣点名称'"))
    private String washPointName;

    @Enumerated(EnumType.STRING)
    @Column(name = "pay_platform", columnDefinition = ("varchar(30) default null comment '支付渠道'"))
    private PayPlatform payPlatform;


    @Column(name = "command")
    private String command;
}
